'use strict';

/* Controllers */
function SysmanageCtrl($scope, $http) {
	$scope.isShowUserRolePop = function($index){
		return ($scope.selectUser == $index);
	}
	// page nav
	$scope.isHavePreNo = function($index){
		return $scope.currentPage > $scope.middlePage;
	}
	$scope.isHaveNextNo = function($index){
		if ($scope.currentPage <= $scope.middlePage){
			return $scope.totalPage > $scope.showPage;
		}else{
			return $scope.currentPage < $scope.totalPage-$scope.middlePage+1;
		}
	}
	$scope.isShowNo = function($index){
		var page = $index+1;
		if ($scope.currentPage <= $scope.middlePage){
			return (page >=1 && page<=$scope.showPage);
		}else if ($scope.currentPage >= $scope.totalPage-$scope.middlePage+1){
			return (page >=$scope.totalPage-$scope.showPage+1);
		}else{
			return (page <= $scope.currentPage+$scope.middlePage-1 && page >= $scope.currentPage-$scope.middlePage+1);
		}
	}
	$scope.goPreNo = function(){
		if ($scope.currentPage > 1){
			$scope.currentPage -= 1;
		}
	}
	$scope.goNextNo = function(){
		if ($scope.currentPage < $scope.totalPage){
			$scope.currentPage += 1;
		}
	}
	$scope.goPageNo = function($index){
		$scope.currentPage = $index+1;
	}

	$scope.setClickYzmain = function($index){
		$scope.selectUser = null;
	}
	$scope.setSelectUser = function($index, $event){
		if (!$scope.isShowUserRolePop($index)){
			$scope.selectUser = $index;
		}else{
			$scope.selectUser = null;
		}
		$event.stopPropagation();
	}
	//init parameters
	$scope.setMenu(3);
	$scope.roles = ["一级管理员", "二级管理员", "普通用户"];
	$scope.users = [
	{name : "杨朝来", role : 0},
	{name : "唐灿华", role : 1},
	{name : "赵小雪", role : 1},
	{name : "曹继梅", role : 2},
	{name : "范文苑", role : 2},
	{name : "吴卫国", role : 2},
	{name : "杨金金", role : 2},
	{name : "岑明珠", role : 2},
	{name : "陈才乾", role : 2}
	];

	$scope.totalPage = 10;
	$scope.currentPage = 1;
	$scope.showPage = 7;
	$scope.middlePage = Math.ceil($scope.showPage/2);
	$scope.PageNos = [];
	for (var i = 0; i < $scope.totalPage; i++){
		$scope.PageNos.push(i+1); 
	}
	
}

